<template>
	<view>
		<uni-section title="悬赏汇总" type="line">
			<uni-search-bar placeholder="请输入悬赏名" bgColor="#EEEEEE" @confirm="search" v-model="searchParams" @cancel="searchCancel"/>
			<template v-for="(i, index) in list">
			<uni-card :cover="cover"  @click="onClick(index)">
				<template v-slot:title>
					<uni-list>
						<uni-list-item :show-switch="false" :title="i.title" />
					</uni-list>
				</template>
				<text class="uni-body">{{i.requirementDescription}}</text>
				<view slot="actions" class="card-actions">
				</view>
				<view class="footer-box">
					<view class="footer-box left">${{i.money}}
					</view>
					<view class="footer-box content">发布者:{{i.bountyGiverName}}
					</view>
					<view class="footer-box right">
						种类:{{i.type}}
					</view>
				</view>
			</uni-card>
			</template>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				cover: '/static/images/cover/cover1.jpg',
				extraIcon: {
					color: '#4cd964',
					size: '22',
					type: 'gear-filled'
				},
				icon_like_show: false,
				list: [],
				searchParams:'',
				searchUrl:'http://xg.kystu.cn:8085/system/reward/RewardList?flag=2'
			}
		},
		methods: {
			searchCancel(){
				var _this=this;
				_this.searchParams=null
				_this.search();
			},
			search(){
				var _this=this;
				if(_this.searchParams!=null&&_this.searchParams!=''){
					_this.searchUrl=_this.searchUrl+'&title='+_this.searchParams
				}
				uni.request({
					url: _this.searchUrl,
					method: "GET",
					header: {
						'Authorization': "Bearer " + _this.token
					},
					success: (res) => {
						if (res.data
							.code ==
							200) {
								_this.searchUrl='http://xg.kystu.cn:8085/system/reward/RewardList'
							uni.showToast({
								title: "查询成功",
								icon: 'exception',
								duration: 850
							});
							console.log(res.data.rows)
							_this.list = res.data.rows;
							for(var i in res.data.rows){
								console.log(res.data.rows[i].requirementDescription)
								_this.list[i].requirementDescription=_this.list[i].requirementDescription.substring(0,30)+'......'
							}
						}
					}
				});
			},
			onClick(i){
				uni.navigateTo({
					url:'/pages/els/content/content7?index=' + i
				});
			},
			actionsClick(text) {
				uni.showToast({
					title: text,
					icon: 'none'
				})
			},
			onShow() {
				var _this = this;
				uni.getStorage({
					key: 'App-Token',
					success(res) {
						_this.token = res.data;
						uni.request({
							url: 'http://xg.kystu.cn:8085/system/reward/RewardList?flag=2',
							method: "GET",
							header: {
								'Authorization': "Bearer " + _this.token
							},
							success: (res) => {
								if (res.data
									.code ==
									200) {
									uni.showToast({
										title: "查询成功",
										icon: 'exception',
										duration: 850
									});
									console.log(res.data.rows)
									_this.list = res.data.rows;
									for(var i in res.data.rows){
										console.log(res.data.rows[i].requirementDescription)
										_this.list[i].requirementDescription=_this.list[i].requirementDescription.substring(0,30)+'......'
									}
								}
							}
						});
					}
				})
			}
		}
	}
</script>

<style>
	.footer-box .left {
		float: left;
		text-align: center;
		width: 20%;
		color: red;
	}

	.footer-box .content {
		float: left;
		text-align: center;
		width: 45%;
	}

	.footer-box .right {
		float: left;
		text-align: center;
		width: 33.3%;
	}
</style>
